package com.siren.tank.group.bad;

import com.siren.tank.Dir;
import com.siren.tank.GameModel;
import com.siren.tank.Group;
import com.siren.tank.TankFrame;
import com.siren.tank.group.Bullet;

import java.awt.*;

/**
 * @author : wangjichao
 * @description:
 * @date : 2020/7/29 10:33
 */
public class BadBullet extends Bullet {


    public BadBullet(int x, int y, Dir dir, Group group, GameModel gm) {
        super(x, y, dir);
        this.group = group;
    }

    @Override
    public void paint(Graphics g) {
        if (!this.live) {
            GameModel.getInstance().remove(this);
            return;
        }
        Color c = g.getColor();
        g.setColor(Color.RED);
        g.fillOval(x, y, 10, 20);
        g.setColor(c);
        move();
    }

    private void move() {
        switch (dir) {
            case LEFT:
                x -= SPEED;
                break;
            case RIGHT:
                x += SPEED;
                break;
            case UP:
                y -= SPEED;
                break;
            case DOWN:
                y += SPEED;
                break;
            default:
                break;
        }

        if (x < 0 || y < 0 || x > TankFrame.WIDTH || y > TankFrame.HEIGHT) {
            this.live = false;
        }

    }

}
